extends Node
class_name ScareCrowState
## 用来控制敌人状态和移动
@export var scare_crow: CharacterBody2D
@onready var enemy_health_component: EnemyHealthComponent = %EnemyHealthComponent
@onready var sprite: AnimatedSprite2D = %sprite
@onready var state_chart: StateChart = %StateChart
@onready var idle: AtomicState = %idle
@onready var hurt: AtomicState = %hurt

func _ready() -> void:
	enemy_health_component.hurt.connect(on_hurt)
	idle.state_physics_processing.connect(on_idle_physics_processing)
	hurt.state_entered.connect(on_hurt_state_entered)
	
func state_send_event(_name: String):
	state_chart.send_event(_name)
	
func on_idle_physics_processing(_delta):
	sprite.play("idle")

func on_hurt_state_entered():
	sprite.play("hurt")
	await sprite.animation_finished
	state_send_event("to_idle")

func on_hurt():
	state_send_event("to_hurt")
